<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<!--公共JS开始-->
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.timer.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<!--公共JS结束-->
<!--数据列表插件开始-->
<link href="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.css" rel="stylesheet" type="text/css" />
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.ui.position.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/ContextMenu/src/jquery.contextMenu.js"></script>
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Css/etgrid.css">
<script src="{$NOW_THEME_URL}/Assets/Plugins/Etgrid/Js/etgrid.js"></script>
<!--数据列表插件结束-->
<style type="text/css">
	body {
		overflow:hidden;
	}
	.table_box {
	}
	.width_200{
		width:250px;
	}
	.btns{
		background-color:#339900;
		color:#FFFFFF;
		padding:2px 4px;
		cursor:pointer;
		float:right;
		margin-right:10px;
	}
</style>
</head>

<body>
	<div class="page_header">
	<div class="table_tool">
		<ul class="clearfix">			
			<li class="memberDel btn"><i class="icon-remove"></i> 批量删除</li>
			<li class="line"></li>
			<li class="memberGroup btn">
				<i class="icon-group"></i><a id="ydz">移动至</a>
				<ul class="submenu">
					<volist name="details" id="vo">
						<li rel="{$vo.id}" title="{$vo.title}"><i class="icon-caret-right"></i>{$vo.title}</li>
					</volist>
				</ul>
			</li>
			<li class="line"></li>
			<li class="openwin btn" etitle="新增会员" eheight="500px" ewidth="900px" ehref="{:U('Custom/add')}" id="Custom_add"><i class="icon-plus"></i> 新增会员</li>
			<li class="line"></li>
			<li class="memberFrost btn">
				<i class="icon-asterisk"></i> 冻结会员
				<ul class="submenu">
					<li toid="frost"><i class="icon-caret-right"></i> 冻结会员</li>
					<li toid="thaw"><i class="icon-caret-right"></i> 会员解冻</li>
				</ul>
			</li>
		</ul>
	</div>
	<div class="search_box">
		性别：
		<select class="form_ele" id="cus_sex" style="width:8%;height:100%;">
			<option value="">请选择</option>
			<option value="1">先生</option>
			<option value="2">女士</option>
		</select>
		会员状态：
		<select class="form_ele" id="cus_status" style="width:8%;height:100%;">
			<option value="">请选择</option>
			<option value="1">正常</option>
			<option value="2">冻结</option>
		</select>
		<input type="text" class="form_ele width_200" id="keywords" name="keywords" placeholder="根据会员姓名、电话、邮箱进行搜索">
		<span class="doSearch searchbtn"><i class="icon-search"></i> 搜索</span>
		<span id="doRest" class="doSearch">
			<i class="icon-search"></i> 重置搜索
		</span>
		<!-- <span class="btns openwin" >批量导出会员</span> 
		<span class="btns openwin" etitle="批量导入会员" eheight="400px" ewidth="800px" ehref="{:U('Custom/import')}" id="Custom_import">批量导入会员</span>-->
	</div>
	
	</div>
	<div class="table_box">
	</div>
</body>
<script type="text/javascript">
	var listConfig = {
			gridId : 'memberList',
			blockBox : '.table_box',
			blockBoxHeight : 'window',
			jsonUrl : '__URL__/index',
			where : '',
	 		getWhere : function(){
	 			return getwheres();
			},
			
			widthType : 'tdw', //thw-标题标准宽度、tdw-数据单元标准宽度、auto-随数据单元宽度
			pageNum : 10,
			nowPage : 1,
			orderName : "addtime",
			orderDirection : "desc",
			dataContextMenuOpen: true, //是否开启数据行右键菜单
			dataContextMenu: function(){
				$.contextMenu({
					selector: '.et_tbody tr',
					items: {
						"view": {
							name: "查看", 
							icon: "edit",
							callback: function(key, options) {
								var href = "{:U('Custom/view')}&id="+$(this).attr('rowid');
								var width = '900px';
								var height = '500px';
								var title = '查看会员资料';
								openDialog('Custom_view',href,width,height,title);
							}
						},
						"edit": {
							name: "修改", 
							icon: "edit",
							callback: function(key, options) {
								var href = "{:U('Custom/edit')}&id="+$(this).attr('rowid');
								var width = '900px';
								var height = '500px';
								var title = '修改会员';
								openDialog('Custom_edit',href,width,height,title);
							}
						},
						"delete": {
							name: "删除", 
							icon: "edit",
							callback: function(key, options) {
								var msg = "确认要删除该会员吗？";
								var id = $(this).attr('rowid');

								windowApi.lhgdialog.confirm(msg, function(){
									$.post("{:U('Custom/del')}",{id:id},function(data){
										$('.et_tfoot .page_refresh').click(); //刷新加载
									});
								},function(){
									return;
								});
							}
						},
						"address": {
							name: "添加地址", 
							icon: "edit",
							callback: function(key, options) {
								var href = "{:U('Custom/address')}&id="+$(this).attr('rowid');
								var width = '900px';
								var height = '500px';
								var title = '添加会员地址';
								openDialog('Custom_address',href,width,height,title);
							}
						},
					}
				});
			},
			colModel : [
				{
					display : 'checkbox',
					name : 'id',
					sortable : false,
					myclass : 'center',
					edit : false
				},
				{
					display : '姓名',
					name : 'realname',
					sortable : true,
					myclass : 'center',
					edit : false,
					width: '100px',
				},
				{
					display : '手机号码',
					name : 'mobile',
					sortable : true,
					myclass : 'center',
					edit : false
				},
				{
					display : '电邮',
					name : 'email',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'200px',
				},
				{
					display : '性别',
					name : 'sex',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'65px',
				},
				{
					display : '状态',
					name : 'status',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'65px',
				},
				{
					display : '注册',
					name : 'isreg',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'65px',
				},
				{
					display : '添加时间',
					name : 'addtime',
					sortable : true,
					myclass : 'center',
					edit : false,
					width:'120px',
				},
			]
		};
	
	//实例化列表
	var tableList = $('.table_box').EtGrid(listConfig);
	//tableList.erefresh();
	
 	//根据会员分组筛选
	$('#cus_groupid>option').each(function(){
		$(this).on('click',function(){
			byCondition();
		});
	});
	//根据性别筛选
	$('#cus_sex>option').each(function(){
		$(this).on('click',function(){
			byCondition();
		});
	});
	//根据会员状态筛选
	$('#cus_status>option').each(function(){
		$(this).on('click',function(){
			byCondition();
		});
	});
	//重置搜索条件
	$("#doRest").on("click",function(){
		clearwheres();
		byCondition();
	});
	
	//根据关键字进行搜索
	$('.searchbtn').on('click',function(data){
		byCondition();
	});
	
	//批量删除
	$('.memberDel').on('click',function(){
		
		var val = tableList.getChecked();
		var msg = "确认要将选中的会员删除吗？";
		
		if(val){
			windowApi.lhgdialog.confirm(msg, function(){
				$.post("{:U('Custom/del')}",{id:val},function(data){
					if(data.status==1){
						$('.et_tfoot .page_refresh').click(); //刷新加载
					}else{
						windowApi.lhgdialog.alert(data.info,function(){return;});
					}
				});
			},function(){
				return;
			});
		}else{
			windowApi.lhgdialog.alert('请选择需要删除的会员！');
		}
	});
	
	$('.updateLevel .submenu>li').on('click',function(){
		var val = tableList.getChecked();
	}); 
	
	//调整会员分组
 	$(".memberGroup .submenu>li").on('click',function(){
		var groupid  = $(this).attr("rel");
		var id  = tableList.getChecked();
		if(id==""){
			windowApi.lhgdialog.alert('您还没有选择任何会员！',function(){return;}); 
		}else{
			$.get("{:U('Custom/groupMove')}",{id:id,groupid:groupid},
	 			function(d){
	 				windowApi.lhgdialog.tips('数据修改成功！',1,etIcon.success,function(){
	 				$('.et_tfoot .page_refresh').click(); //刷新加载
	 			}); 
			}); 
		}
	});
	
	//冻结会员
	$('.memberFrost .submenu>li').on('click',function(){
		
		var val  = tableList.getChecked();
		var toid = $(this).attr('toid');
		
		//冻结/解除冻结
		if(toid=="frost"){
			if(val){
				$.post("{:U('Custom/frost')}",{id:val},function(data){
					if(data.status==1){
						windowApi.lhgdialog.tips('会员冻结成功！',1,etIcon.success,function(){
							$('.et_tfoot .page_refresh').click(); //刷新加载
						});
					}else{
						windowApi.lhgdialog.tips(data.info,1,etIcon.error,function(){
							return;
						});
					}
				});
			}else{
				windowApi.lhgdialog.alert('请选择需要冻结的会员！',function(){return;});
			}
		}else{
			if(val){
				$.post("{:U('Custom/thaw')}",{id:val},function(data){
					if(data.status==1){
						windowApi.lhgdialog.tips('会员解除冻结成功！',1,etIcon.success,function(){
							$('.et_tfoot .page_refresh').click(); //刷新加载
						});
					}else{
						windowApi.lhgdialog.tips(data.info,1,etIcon.error,function(){
							return;
						});
					}
				});
			}else{
				windowApi.lhgdialog.alert('请选择需要解除冻结的会员！',function(){return;});
			}
		}
	});
	
	//获取筛选条件并组成数组
	function getwheres(){
		
		var where  = {};
		where.sex      = $('#cus_sex').val();
		where.status   = $('#cus_status').val();
		where.keywords = $('#keywords').val();
		return where;
	}
	
	//重置搜索条件
	function clearwheres(){
		$('#cus_sex').val("");
		$('#cus_status').val("");
		$('#keywords').val("");
	}
	//发送异步进行搜索
	function byCondition(){
		
		var where = tableList.config.getWhere();
		tableList.config.nowPage = 1;
		tableList.config.where   = where;
		tableList.search();
	}
</script>
</html>
